﻿/**********************************************************************************
 * Project Name :   
 * Remarks      :  
 * Class Name   :  Log4netLog 
 * Version      :  v1.0.0.0 
 * Author       :  Joey Liang 
 * Description  : 
 * Created Time :  2013/8/14 22:36:26
 * Update Man   :  Joey Liang
 * Update Time  :  2013/8/14 22:36:26
************************************************************************/

using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

[assembly:log4net.Config.XmlConfigurator(Watch=true)]
namespace JoeyLibs.Utility.Log
{
    public class Log4netLog : IJoeyLog
    {
        private ILog log;
        public Log4netLog(string loggerName)
        {
            this.log = LogManager.GetLogger(loggerName);            
        }

        public void OutputLog(LogType logType, string message, Exception exception)
        {
            switch (logType)
            {
                case LogType.Debug:
                    if (log.IsDebugEnabled)
                        log.Debug(message, exception);
                    break;

                case LogType.Error:
                case LogType.Exception:
                    if (log.IsErrorEnabled)
                        log.Error(message, exception);
                    break;

                case LogType.Fatal:
                    if (log.IsFatalEnabled)
                        log.Fatal(message, exception);
                    break;

                case LogType.Performance:
                case LogType.Warn:
                    if (log.IsWarnEnabled)
                        log.Warn(message, exception);
                    break;

                default:
                    if (log.IsInfoEnabled)
                        log.Info(message, exception);
                    break;
            }
        }

        public void OutputLog(string msg)
        {
            log.Info(msg);
        }
    }
}
